using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using System;
namespace MicroMsg.Scene
{
	public class NetSceneGetAppInfo : NetSceneBaseEx<GetAppInfoRequest, GetAppInfoResponse, GetAppInfoRequest.Builder>
	{
		private const string TAG = "NetSceneGetAppInfo";
		public bool doScene(string appID, MMAppInfoIconType iconType)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.IconType = (uint)iconType;
			this.mBuilder.AppID = appID;
			this.mSessionPack.mCmdUri = "/cgi-bin/micromsg-bin/getappinfo";
			this.mSessionPack.mConnectMode = 2;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(GetAppInfoRequest request, GetAppInfoResponse response)
		{
			Log.smethod_1("NetSceneGetAppInfo", "send request failed");
			EventCenter.postEvent(EventConst.ON_NETSCENE_GET_APPINFO_ERR, RetConst.MM_ERR_CLIENT, null);
		}
		protected override void onSuccess(GetAppInfoRequest request, GetAppInfoResponse response)
		{
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret != RetConst.MM_OK)
			{
				Log.smethod_1("NetSceneGetAppInfo", "send request failed ret =" + ret);
				EventCenter.postEvent(EventConst.ON_NETSCENE_GET_APPINFO_ERR, ret, null);
				return;
			}
			AppInfo appInfo = new AppInfo();
			appInfo.AppID = response.AppInfo.AppID;
			appInfo.AppName = response.AppInfo.AppName;
			appInfo.AppDescription = response.AppInfo.AppDescription;
			appInfo.AppIconUrl = response.AppInfo.AppIconUrl;
			appInfo.AppStoreUrl = response.AppInfo.AppStoreUrl;
			appInfo.AppVersion = response.AppInfo.AppVersion;
			appInfo.AppWatermarkUrl = response.AppInfo.AppWatermarkUrl;
			EventCenter.postEvent(EventConst.ON_NETSCENE_GET_APPINFO_SUCCESS, appInfo, null);
			AppInfoMgr.saveAppInfo(appInfo);
		}
	}
}
